<!--
 * @Description: 库存维护
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:54:18
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span v-if="UserInfo.adminStatus == 1">
                  <span style="margin-right: 12px">公司</span>
                  <el-select ref="selection1" v-model="tableParam.companyId" placeholder="请选择" style="width:150px;" @change="setstationIdlist(),$nextTick(()=>{tableParam.company = $refs.selection1.selectedLabel})">
                    <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </span>
                <span style="display: inline-block;margin-bottom: 10px;margin-left: 24px;">
                  <span style="margin-right: 12px">站点</span>
                  <el-select ref="selection2" v-model="tableParam.stationId" clearable placeholder="请选择" style="width:150px;" @change="get_simple_organizationFun(tableParam.stationId),$nextTick(()=>{tableParam.stationName = $refs.selection2.selectedLabel}),changeStation(tableParam.stationId, 0)">
                    <el-option v-for="item in stationIdlist0" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">仓库</span>
                  <el-select v-model="tableParam.warehouseId" clearable placeholder="请选择" style="width:150px;">
                    <el-option v-for="(item, index) in arr1" :key="index" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">物料</span>
                  <el-select v-model="tableParam.rawNameId" clearable style="width:150px;" placeholder="请选择">
                    <el-option v-for="(item, index) in rawList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='XJCK'))!==-1" size="small" class="bottom_all" style="margin-left: 0" @click="addFromDate('添加'), initRaw()">
                  <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                  初建库存
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='WLDB'))!==-1" size="small" class="bottom_three" @click="open('Dialog2', '')">
                  物料调拨
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='PDJL'))!==-1" size="small" class="bottom_three" @click="queryTransferPageFun()">
                  调拨记录
                </el-button>
              </div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">
                        {{ item.label }}
                      </el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width">
                    <template slot-scope="scope">
                      <span v-if="item.label == '操作'">
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='KCPD'))!==-1" size="mini" class="bottom_one" @click="handleInventory(scope.row)">
                          库存盘点
                        </el-button>
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='KCMX'))!==-1" size="mini" class="bottom_one" @click="open('Dialog3', scope.row)">库存明细</el-button>
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='PDJL'))!==-1" size="mini" class="bottom_one" @click="open('Dialog4', scope.row)">盘点记录</el-button>
                        <el-button size="mini" class="bottom_one" @click="handleDelete(scope.row)">删除</el-button>
                      </span>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
            <div class="card_bottom">
              <div class="card_bottom_left">
                <div class="top_page_totle">总共{{ total }}条</div>
                <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
              </div>
              <div>
                <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
              </div>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
    <!-- 初建库存 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="480px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="stationId">
            <span slot="label" style="color: #ff0000">站点</span>
            <el-select v-model="fromDate.stationId" placeholder="请选择" @change="changeStation(fromDate.stationId, 1)">
              <el-option v-for="item in stationIdlist0" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="warehouseId">
            <span slot="label" style="color: #ff0000">仓库编码</span>
            <el-select v-model="fromDate.warehouseId" placeholder="请选择" @change="changeStore(fromDate.warehouseId, 1)">
              <el-option v-for="(item, index) in arr1" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="rawId">
            <span slot="label" style="color: #ff0000">物料名称</span>
            <el-select v-model="fromDate.rawId" placeholder="请选择">
              <el-option v-for="(item, index) in arr2" :key="index" :label="item.name+'_'+item.specification+'_'+item.brand" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="price">
            <span slot="label" style="color: #ff0000">价格</span>
            <el-input v-model="fromDate.price" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item prop="stock">
            <span slot="label">库存数量(吨)</span>
            <el-input-number v-model="fromDate.stock" style="width:240px;" :max="fromDate.maxStock" type="Number" :disabled="fromDate.maxStock == 0" placeholder="请输入" clearable></el-input-number>
          </el-form-item>
          <el-form-item label="仓库最大库存">
            <span>{{fromDate.maxStock}}</span>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="pagessubmitFromDate()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 库存盘点 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog1" width="550px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">库存盘点</span>
      <div class="dialoginfo">
        <el-form ref="reffrom1" :rules="rules1" :model="from1" label-width="140px">
          <el-form-item prop="stationId">
            <span slot="label" style="color: #ff0000">站点</span>
            <el-select ref="from1_station" v-model="from1.stationId" disabled placeholder="请选择" style="width: 280px">
              <el-option v-for="item in stationIdlist0" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="updateTime">
            <span slot="label" style="color: #ff0000">盘点时间</span>
            <el-date-picker v-model="from1.updateTime" style="width: 280px" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item prop="warehouseId">
            <span slot="label" style="color: #ff0000">盘点仓库</span>
            <span>{{ from1.warehouse }}</span>
          </el-form-item>
          <el-form-item prop="rawId">
            <span slot="label" style="color: #ff0000">盘点物料名称</span>
            <span>{{ from1.raw }}</span>
          </el-form-item>
          <el-form-item prop="stock">
            <span slot="label">盘点库存数量(吨)</span>
            <el-input-number v-model="from1.stock" :controls="false" style="width:240px;" :max="from1.maxStock" placeholder="请输入" clearable></el-input-number>
          </el-form-item>
          <el-form-item prop="code">
            <span slot="label">盘点人员</span>
            <span>{{ UserInfo.userRealName }}</span>
          </el-form-item>
          <el-form-item prop="remark">
            <span slot="label">备注</span>
            <el-input v-model="from1.remark" type="textarea" :rows="5" resize="none" placeholder="请输入" style="width: 280px" maxlength="50" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog1 = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit1()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物料调拨 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog2" width="500px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">物料调拨</span>
      <div class="dialoginfo">
        <el-form ref="reffrom2" :rules="rules2" :model="from2" label-width="120px">
          <el-form-item prop="outsStationId">
            <span slot="label" style="color: #ff0000">站点</span>
            <el-select v-model="from2.outsStationId" placeholder="请选择" @change="changeStation(from2.outsStationId, 3)">
              <el-option v-for="item in stationIdlist0" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="warehouseId">
            <span slot="label" style="color: #ff0000">选择仓库</span>
            <el-select ref="from2_warehouse" v-model="from2.warehouseId" placeholder="请选择" @change="changeStore(from2.warehouseId, 3),$nextTick(()=>{from2.warehouse = $refs.from2_warehouse.selectedLabel})">
              <el-option v-for="(item, index) in arr1" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="rawId">
            <span slot="label" style="color: #ff0000">物料名称</span>
            <el-select v-model="from2.rawId" placeholder="请选择" @change="changeRow(from2.rawId)">
              <el-option v-for="(item, index) in from2_arr1" :key="index" :label="`${item.name}-${item.specification}-${item.brand}`" :value="item.rawId"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="cutToNum">
            <span slot="label">调拨数量(吨)</span>
            <el-input-number v-model="from2.cutToNum" :controls="false" style="width:240px;" :max="from2.maxStock" placeholder="请输入" clearable></el-input-number>
          </el-form-item>
          <el-form-item label="仓库最大库存">
            <span>{{from2.maxStock}}</span>
          </el-form-item>
          <el-form-item v-if="UserInfo.adminStatus == 1" prop="companyId" :rules="[
                  {
                    required: true,
                    message: '请选择接收公司',
                    trigger: 'blur',
                  },
                ]">
            <span slot="label">接收公司</span>
            <el-select v-model="from2.companyId" placeholder="请选择" style="width:280px;" @change="setstationIdlist2()">
              <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="intoStationId">
            <span slot="label">接收站点</span>
            <el-select v-model="from2.intoStationId" placeholder="请选择" style="width: 280px" @change="chaneStore2(from2.intoStationId)">
              <el-option v-for="(item, index) in stationIdlist0" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="intoStationId">
            <span slot="label">接收库存仓</span>
            <el-select ref="from2Warehouse" v-model="from2.recWarehouseId" placeholder="请选择" style="width: 280px" @change="$nextTick(()=>{from2.recWarehouse = $refs.from2Warehouse.selectedLabel})">
              <el-option v-for="(item, index) in houseList" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="remark">
            <span slot="label">备注</span>
            <el-input v-model="from2.remark" type="textarea" :rows="5" resize="none" placeholder="请输入" style="width: 280px" maxlength="50" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog2 = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit2()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 库存明细 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog3" width="880px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">库存明细</span>
      <div>
        <div class="dialoginfo-title">
          <div>
            <span>站点：</span>
            <span>{{ low.stationName }}</span>
          </div>
          <div>
            <span>库存仓：</span>
            <span>{{ low.warehouseName }}</span>
          </div>
          <div>
            <span>原物料：</span>
            <span>{{ low.rawName }}</span>
          </div>
          <div>
            <span>规格：</span>
            <span>{{ low.specification }}</span>
          </div>
          <div>
            <span>品牌：</span>
            <span>{{ low.brand }}</span>
          </div>
        </div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="table1" tooltip-effect="dark">
          <el-table-column label="库存更新时间" align="center" prop="updateTime"></el-table-column>
          <el-table-column label="更新类型" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.checkedStatus==1">盘点调整</div>
              <div v-if="scope.row.checkedStatus==2">添加入库</div>
              <div v-if="scope.row.checkedStatus==3">调拨入库</div>
              <div v-if="scope.row.checkedStatus==4">过磅入库</div>
              <div v-if="scope.row.checkedStatus==5">消耗出库</div>
              <div v-if="scope.row.checkedStatus==6">调拨出库</div>
              <div v-if="scope.row.checkedStatus==7">异常消耗出库</div>
              <div v-if="scope.row.checkedStatus==8">盘点调整出库</div>
              <div v-if="scope.row.checkedStatus==9">冲销</div>
              <div v-if="scope.row.checkedStatus==10">退货</div>
              <div v-if="scope.row.checkedStatus==11">过磅调整（增加）</div>
              <div v-if="scope.row.checkedStatus==12">过磅调整（扣减）</div>
            </template>
          </el-table-column>
          <el-table-column label="入库量（吨）" align="center" prop="receipt"></el-table-column>
          <el-table-column label="出库量（吨）" align="center" prop="outboundQuantity"></el-table-column>
          <el-table-column label="盘点调整库存（吨）" align="center" prop="checkInventory"></el-table-column>
          <el-table-column label="当前库存量（吨）" align="center" prop="currentInventory"></el-table-column>
        </el-table>
        <div class="pagination">
          <div class="top_page_totle">总共{{ tabletatol }}条</div>
          <el-pagination :current-page.sync="tablefrom.page" :page-size="tablefrom.pageSize" layout="prev, pager, next, jumper" :total="tabletatol" @current-change="gettable1()"></el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog3 = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 盘点记录 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog4" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">盘点记录</span>
      <div>
        <div class="dialoginfo-title">
          <div>
            <span>站点：</span>
            <span>{{ low.stationName }}</span>
          </div>
          <div>
            <span>库存仓：</span>
            <span>{{ low.warehouseName }}</span>
          </div>
          <div>
            <span>原物料名称：</span>
            <span>{{ low.rawName }}</span>
          </div>
        </div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="table2" tooltip-effect="dark">
          <el-table-column label="盘点前库存(吨)）" align="center" width="125" prop="beforeCheckInventory"></el-table-column>
          <el-table-column label="盘点后库存(吨)" align="center" width="125" prop="checkInventory"></el-table-column>
          <el-table-column label="盘点盈亏" align="center" width="165" prop="quantityVariance"></el-table-column>
          <el-table-column label="盘点人员" width="125" align="center" prop="updateUserName"></el-table-column>
          <el-table-column label="盘点时间" align="center" width="165" prop="updateTime"></el-table-column>
          <el-table-column label="备注" align="center" prop="remark"></el-table-column>
        </el-table>
        <div class="pagination">
          <div class="top_page_totle">总共{{ tabletatol }}条</div>
          <el-pagination :current-page.sync="tablefrom.page" :page-size="tablefrom.pageSize" layout="prev, pager, next, jumper" :total="tabletatol" @current-change="gettable2()"></el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog4 = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog v-dialogDrag :visible.sync="look4Type" width="1200px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">调拨记录</span>
      <div class="dialoginfo">
        <el-table ref="look2List" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="list4" tooltip-effect="dark" highlight-current-row>
          <el-table-column prop="warehouse" label="库存仓" width="auto" align="center"></el-table-column>
          <el-table-column prop="rawName" label="原物料" width="auto" align="center"></el-table-column>
          <el-table-column prop="specification" label="规格" width="auto" align="center"></el-table-column>
          <el-table-column prop="brand" label="品牌" width="auto" align="center"></el-table-column>
          <el-table-column prop="stock" label="当前库存数量(吨)" width="auto" align="center"></el-table-column>
          <el-table-column prop="transferNum" label="调拨数量" width="auto" align="center"></el-table-column>
          <el-table-column prop="recStation" label="接收站点" width="auto" align="center"></el-table-column>
          <el-table-column prop="remark" label="备注" width="160" align="center"></el-table-column>
          <el-table-column prop="createTime" label="调拨时间" width="160" align="center"></el-table-column>
        </el-table>
        <div class="card_bottom">
          <div class="card_bottom_left">
            <div class="top_page_totle">总共{{ table4Param.total }}条</div>
            <el-pagination :current-page.sync="table4Param.page" :page-size="table4Param.pageSize" layout="prev, pager, next, jumper" :total="table4Param.total" @current-change="queryTransferPageFun()"></el-pagination>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="look4Type=false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  saveOrUpdate,
  Download,
  //update_check_inventory,
  check_detail,
  inventory_detail,
  get_station_list,
  // update_raw_allocation,
  selectRoles,
  getStockNumber,
  queryTransferPage,
  updateInventory,
} from "@/api/smart/stocksake.js";
import { warehousePage } from "@/api/basicConfig/site.js";
import { queryMaterialsPage } from "@/api/basicConfig/Rmaterial.js";
import { getUserInfo } from "@/utils/auth.js";
import { getcompany, getDicType, getStationByCompanyId, get_simple_organization, getUserAutList } from "@/api/common.js";
export default {
  mixins: [mixin],
  data() {
    return {
      table4Param: {
        dataId: '',
        page: 1,
        pageSize: 10,
        total: 0
      },
      look4Type: false,
      list4: [],
      UserInfo: '',
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      saveOrUpdate: saveOrUpdate,
      DownloadURL: Download,
      /*表格数据*/
      table: [
        { label: "站点", width: "auto", prop: "stationName", status: true },
        { label: "库存号", width: "120", prop: "warehouseName", status: true },
        { label: "物料名称", width: "auto", prop: "rawName", status: true },
        { label: "规格", width: "auto", prop: "specification", status: true },
        { label: "品牌", width: "auto", prop: "brand", status: true },
        {
          label: "库存量（吨）",
          width: "120",
          prop: "currentInventory",
          status: true,
        },
        { label: "盘点时间", width: "auto", prop: "updateTime", status: true },
        { label: "操作", width: "400", prop: "", status: true },
      ],
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        warehouseId: [
          { required: true, message: "请选择仓库", trigger: "change" },
        ],
        rawId: [{ required: true, message: "请选择原物料", trigger: "change" }],
        stock: [{ required: true, message: "请输入库存数量", trigger: "blur" }],
        price: [
          { required: true, message: "请输入价格", trigger: "blur" },
        ],
      },
      fromDate: {
        maxStock: 0,
        warehouseId: '',
        rawId: '',
        price: '',
      },
      low: {},
      Dialog1: false,
      Dialog2: false,
      Dialog3: false,
      Dialog4: false,
      from1: {
        rawId: "",
        warehouseId: '',
        stock: '',
        updateTime: '',
      },
      from1_arr1: [],
      from2: {
        rawId: "",
        maxStock: 0,
        warehouseId: '',
        intoStation: '',
        outsStation: '',
        rawName: '',
        recWarehouse: '',
        recWarehouseId: '',
      },
      from2_arr1: [],
      rules1: {
        warehouseId: [
          { required: true, message: "请选择仓库", trigger: "change" },
        ],
        rawId: [{ required: true, message: "请选择原物料", trigger: "change" }],
        stock: [
          { required: true, message: "请输入盘点库存数量", trigger: "blur" },
        ],
        updateTime: [
          { required: true, message: "请选择盘点时间", trigger: "change" },
        ],
      },
      rules2: {
        warehouseId: [
          { required: true, message: "请选择仓库", trigger: "change" },
        ],
        rawId: [{ required: true, message: "请选择原物料", trigger: "change" }],
        cutToNum: [
          { required: true, message: "请输入调拨数量", trigger: "blur" },
        ],
        intoStationId: [
          { required: true, message: "请选择转入站点", trigger: "change" },
        ],
      },
      tablefrom: {
        page: 1,
        pageSize: 10,
        rawId: "",
      },
      tabletatol: 0,
      table1: [],
      table2: [],
      arr1: [],
      arr2: [],
      houseList: [],
      companylist: [],
      stationIdlist: [],
      stationIdlist0: [],
      User: "",
      rawList: [],
    };
  },
  deactivated() {
    this.Dialog1 = false
    this.Dialog2 = false
    this.Dialog3 = false
    this.Dialog4 = false
  },
  async created() {
    this.UserInfo = await getUserInfo();
    if (this.UserInfo.adminStatus == 1) {
      /**通过typeId为公司类型id查询所有公司 */
      getcompany({ typeId: "19da56b9e85648059e3cf1e7da497da4" }).then((res) => {
        this.companylist = res.data;
      });
    } else {
      this.stationIdlist0 = await getUserAutList(true)
      getStationByCompanyId({ id: this.UserInfo.companyId }).then((res) => {
        if (res.data ?.length > 0) {
          this.stationIdlist = res.data.map(v => ({ name: v.stationName, id: v.stationId }))
        }
      })
    }
    /**通过typeId为公司类型id查询所有公司 */
    getcompany({ typeId: "19da56b9e85648059e3cf1e7da497da4" }).then((res) => {
      this.companylist = res.data;
    });
    this.tableParam = {
      ...this.tableParam,
      warehouseId: "",
      rawId: "",
    };
    this.gettableData();
    getDicType({ code: "MATname" }).then((res) => {
      this.rawList = res.data.items;
    });
  },
  methods: {
    handleInventory (data) {
      this.Dialog1 = true;
      this.from1 = {
        stationId: data.stationId,
        station: data.stationName,
        updateTime: '',
        warehouseId: data.warehouseId,
        warehouse: data.warehouseName,
        rawId: data.rawId,
        raw: data.rawName,
        stock: '',
        remark: '',
      }
    },
    initRaw () {
      queryMaterialsPage().then((res) => {
        this.arr2 = res.data;
      });
    },
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      this.tableParam.warehouseId = ''
      this.tableParam.rawNameId = ''
      get_simple_organization({ id: id }).then((res) => {
        this.fromDate.companyId = res.data.id
        this.fromDate.company = res.data.name
      });//查询站点所属公司
    },
    /*根据公司获取站点*/
    setstationIdlist() {
      if (this.tableParam.companyId) {
        get_station_list({ parentId: this.tableParam.companyId }).then((res) => {
          this.stationIdlist0 = res.data;
        });
      }
    },
    /*根据公司获取站点2*/
    setstationIdlist2() {
      if (this.tableParam.companyId) {
        get_station_list({ parentId: this.tableParam.companyId }).then((res) => {
          this.stationIdlist0 = res.data;
        });
      }
    },
    init() {
      /*重置数据*/
      this.tableParam.companyId = ""
      this.tableParam.stationId = ""
      this.tableParam.warehouseId = "";
      this.tableParam.rawNameId = "";
      this.gettableData();
    },
    open(key, low) {
      this.low = low;
      if (key == "Dialog1") {
        this[key] = true;
        this.$data.from1 = this.$options.data().from1;
        setTimeout(() => {
          this.$refs.reffrom1.clearValidate();
        }, 10);
        return;
      }
      if (key == "Dialog2") {
        this[key] = true;
        this.$data.from2 = this.$options.data().from2;
        setTimeout(() => {
          this.$refs.reffrom2.clearValidate();
        }, 10);
        return;
      }
      if (key == "Dialog3") {
        this.tablefrom = this.$options.data().tablefrom;
        this.gettable1();
        this[key] = true;
        return;
      }
      if (key == "Dialog4") {
        this.tablefrom = this.$options.data().tablefrom;
        this.gettable2();
        this[key] = true;
        return;
      }
      this[key] = true;
    },
    handleDelete (data) {
      const self = this;
      this.$confirm('此操作将永久删除该信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'bottom_all_two',
        confirmButtonClass: 'bottom_all',
        type: 'warning'
      }).then(() => {
        updateInventory({id: data.rawWarehouseId, status: 0}).then(res => {
          if (res.code === 1001) {
            self.$message.success('删除成功');
            self.gettableData();
          }
        })

      }).catch(()=>{
      })
    },
    /**
     * @Description: 切换站点获取
     * @Param: 
     * @Author: wangwangwang
     */
    changeStation(stationId, type) {
      warehousePage({ stationId }).then((res) => {
        if (res.code === 1001) {
          this.arr1 = res.data;
          if (type === 0) {
            this.arr1 = res.data
          } else if (type === 1) {
            this.fromDate.warehouseId = '';
          } else if (type === 3) {
            this.from2.warehouseId = '';
            this.from2.rawId = ''
            this.from2.outsStation = this.stationIdlist0.find(item => item.id === stationId).name;
          }
        }
      });
    },
    chaneStore2(stationId) {
      this.from2.intoStation = this.stationIdlist0.find(item => item.id === stationId).name;
      this.from2.companyId = this.UserInfo.companyId;
      warehousePage({stationId}).then(res => {
        if (res.code === 1001) {
          this.houseList = res.data;
        }
      })
    },
    changeRow(id) {
      this.from2.rawName = this.from2_arr1.find(item => item.rawId === id).name;
      const params = {
        warehouseId: this.from2.warehouseId,
        rawId: this.from2.rawId,
      }
      getStockNumber(params).then(res => {
        if (res.code === 1001) {
          this.from2.maxStock = res.data.stock || 0;
        }
      })
    },
    /*库存盘点*/
    submit1() {
      let _this = this;
      _this.$refs.reffrom1.validate((valid) => {
        if (valid) {
          this.from1.userName = this.UserInfo.userRealName
          this.from1.userId = this.UserInfo.userId
          this.$router.push({ name: "sign_stocksake1", query: { ...this.from1, type: 1 } })
        } else {
          return false;
        }
      });
    },
    /*调拨*/
    submit2() {
      let slef = this;
      slef.$refs.reffrom2.validate((valid) => {
        if (valid) {
          if (slef.from2.intoStationId === slef.from2.outsStationId) {
            slef.$message.warning('调拨站点和接收站点不能相同');
            return
          }
          this.$router.push({ name: "sign_stocksake2", query: { ...slef.from2, type: 1 } })
          // update_raw_allocation(slef.from2).then((res) => {
          //   if (res.code === 1001) {
          //     slef.$message.success('调拨成功');
          //     slef.Dialog2 = false;
          //   }
          //});
        } else {
          return false;
        }
      });
    },
    /*库存盘点记录*/
    gettable2() {
      check_detail({
        ...this.tablefrom,
        warehouseId: this.low.warehouseId,
        rawId: this.low.rawId,
      }).then((res) => {
        this.table2 = res.data.data;
        this.tabletatol = res.data.totalRows;
      });
    },
    /*库存明细*/
    gettable1() {
      inventory_detail({
        ...this.tablefrom,
        warehouseId: this.low.warehouseId,
        rawId: this.low.rawId,
      }).then((res) => {
        this.table1 = res.data.data;
        this.tabletatol = res.data.totalRows;
      });
    },
    /*数据联动*/
    getarr1() {
      warehousePage({ stationId: this.tableParam.stationId }).then((res) => {
        this.arr1 = res.data;
        this.tableParam.warehouseId = "";
        this.tableParam.rawNameId = "";
      });
    },
    changeStore(id, type) {
      // this.fromDate.stock = null;
      selectRoles({ id }).then((res) => {
        if (res.code === 1001) {
          if (type === 1) {
            this.fromDate.maxStock = this.arr1.find(item => item.id === id).stock || 0;
          } else if (type === 2) {
            this.from1_arr1 = res.data;
            this.from1.rawId = ''
            this.from1.maxStock = this.arr1.find(item => item.id === id).stock || 0;
          } else if (type === 3) {
            this.from2_arr1 = res.data;
            this.from2.maxStock = this.arr1.find(item => item.id === id).stock || 0;
            this.from2.rawId = '';
          }
          if(this.fromDate.stock > this.fromDate.maxStock) this.fromDate.stock = this.fromDate.maxStock;
          if (!res.data.length && type !== 1) {
            this.from2.warehouseId = ''
            this.$message.warning('该仓库下原物料为空，请重新选择仓库')
          }
        }
      })
    },
    /*初见仓库*/
    pagessubmitFromDate() {
      const self = this;
      self.$refs.reffromDate.validate((valid) => {
        if (valid) {
          saveOrUpdate(self.fromDate).then((res) => {
            if (res.code === 1001) {
              self.$message({
                message: res.codeMsg,
                type: "success",
              });
              self.resetFromDate();
              self.gettableData();
              self.getarr1();
            }
          });
        }
      });
    },
    queryTransferPageFun() {
      this.look4Type = true
      queryTransferPage(this.table4Param).then((res) => {
        this.list4 = res.data.data
        this.table4Param.total = res.data.totalRows
      })
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },

};
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 240px;
}
.table_link {
  margin: 0 10px;
  color: $bg_color;
}
.dialoginfo-title {
  display: flex;
  justify-content: space-between;
  padding: 10px 0 20px 0;
  font-weight: bold;
}
.table_link:hover {
  opacity: 0.8;
}
</style>
